package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwBannerService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by BKWJA on 2018/12/20.
 * 轮播图管理控制层
 */
@Api(value = "XwBannerController",tags = "轮播图接口类")
@Slf4j
@RequestMapping("banner")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwBannerController extends IMoocExceptionHandler {

    @Autowired
    private XwBannerService xwBannerService;


    /**
     * 轮播图列表查询
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @return
     */
    @ApiOperation(value = "XW_轮播图列表查询")
//    @ApiImplicitParams({@ApiImplicitParam(name = "pageindex",value = "当前页,默认为1")})
    @RequestMapping("/getbannerlist")
    @ResponseBody
    public JSONObject getbannerlist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                      @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                      @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                      @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                      @RequestParam(value = "sortfild",defaultValue = "banner_createtime") String sortfild,
                                      @RequestParam(value = "sortway",defaultValue = "desc")String sortway){
        return xwBannerService.getbannerlist(pageindex,pagesize,starttime,endtime,sortfild,sortway);
    }

    /**
     * 修改，新增轮播图信息
     * @param banner_encryptId  轮播图加密id
     * @param banner_img 图片链接地址
     * @param banner_desc 描述
     * @return
     */
    @RequestMapping("/updatebanner")
    @ResponseBody
    public JSONObject updatebanner(String banner_encryptId,String banner_img,String banner_desc){
        return xwBannerService.updatebanner(banner_encryptId,banner_img,banner_desc);
    }

    /**
     * 删除
     * @param banner_encryptId
     * @return
     */
    @RequestMapping("/delbanner")
    @ResponseBody
    public JSONObject delbanner(String banner_encryptId){
        return xwBannerService.delbanner(banner_encryptId);
    }

    /**
     * 根据轮播id，获取获取轮播图片,打包下载图片素材
     * @param banner_encryptId
     * @return
     */
    @RequestMapping("/getBannerByEncryptId")
    @ResponseBody
    public JSONObject getBannerByEncryptId(String banner_encryptId){
        return xwBannerService.getBannerByEncryptId(banner_encryptId);
    }


}
